package org.cloudnote.controller;

import org.cloudnote.service.NoteService;
import org.cloudnote.util.NoteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/note")
public class NoteController {
    @Autowired
    private NoteService noteService;
    @RequestMapping("/search.do")
    @ResponseBody
    public  NoteResult searchNote(String keyword){
        NoteResult result = noteService.searchShare(keyword);
        return  result;
    }

    @RequestMapping("/share.do")
    @ResponseBody
    public  NoteResult shareNote(String noteId){
        NoteResult result = noteService.shareNote(noteId);
        return  result;
    }

    @ResponseBody
    @RequestMapping("/recycle.do")
    public NoteResult recycleNote(String noteId){
        //System.out.println("=====================" + noteId);
        NoteResult result = noteService.recycleNote(noteId);
        return result;
    }

    @ResponseBody
    @RequestMapping("/update.do")
    public NoteResult updateNote(String noteTitle ,String noteBody,String  noteId){
//        System.out.println(noteTitle);
//        System.out.println(noteBody);
//        System.out.println(noteId);
        //System.out.println("=====================" + noteTitle);
        NoteResult result = noteService.updateNote(noteTitle ,noteBody,noteId);
        return result;
    }

    @ResponseBody
    @RequestMapping("/add.do")
    public NoteResult addNote(String bookId,String userId,String noteTitle){
        NoteResult result = noteService.addNote(bookId, userId,noteTitle);
        return result;
    }

    @RequestMapping("/load.do")
    @ResponseBody
    public NoteResult loadNoteDetail(String noteId){
        NoteResult result = noteService.loadNoteDetail(noteId);
        return result;
    }

    @RequestMapping("/loadnotes.do")
    @ResponseBody
    public NoteResult loadNotes(String bookId){
        NoteResult result = noteService.loadBookNotes(bookId);
        return result;
    }
}
